// 等待DOM加载完成
document.addEventListener('DOMContentLoaded', () => {
    // 平滑滚动
    document.querySelectorAll('a[href^="#"]').forEach(anchor => {
        anchor.addEventListener('click', function (e) {
            e.preventDefault();
            const target = document.querySelector(this.getAttribute('href'));
            if (target) {
                target.scrollIntoView({
                    behavior: 'smooth',
                    block: 'start'
                });
            }
        });
    });
    // 导航栏滚动效果
    window.addEventListener('scroll', () => {
        const navbar = document.querySelector('.navbar');
        if (window.scrollY > 50) {
            navbar.style.background = 'rgba(255, 255, 255, 0.98)';
            navbar.style.boxShadow = '0 2px 20px rgba(0, 0, 0, 0.1)';
        } else {
            navbar.style.background = 'rgba(255, 255, 255, 0.95)';
            navbar.style.boxShadow = '0 2px 20px rgba(0, 0, 0, 0.05)';
        }
    });

    // 表单提交处理
    const form = document.querySelector('.contact-form form');
    if (form) {
        form.addEventListener('submit', (e) => {
            e.preventDefault();
            alert('感谢您的留言！我们会尽快回复您。');
            form.reset();
        });
    }

    // 滚动动画
    const observerOptions = {
        threshold: 0.1,
        rootMargin: '0px 0px -50px 0px'
    };

    const observer = new IntersectionObserver((entries) => {
        entries.forEach(entry => {
            if (entry.isIntersecting) {
                entry.target.style.opacity = '1';
                entry.target.style.transform = 'translateY(0)';
            }
        });
    }, observerOptions);

    // 观察所有卡片元素
    document.querySelectorAll('.about-card, .activity-card, .gallery-item').forEach(el => {
        el.style.opacity = '0';
        el.style.transform = 'translateY(30px)';
        el.style.transition = 'all 0.6s ease';
        observer.observe(el);
    });

    // "探索更多"按钮功能
    const exploreBtn = document.querySelector('.hero .btn-primary');
    if (exploreBtn) {
        exploreBtn.addEventListener('click', () => {
            document.querySelector('#about').scrollIntoView({
                behavior: 'smooth'
            });
        });
    }

    // 活动详情数据
    const activityDetails = {
        academic: {
            icon: '📚',
            title: '学术研讨',
            date: '2025年',
            content: `
                <p>为了提升同学们的专业素养和学术能力，我们定期组织学术研讨活动。</p>
                <h3>活动特色</h3>
                <p>• 邀请专业老师指导，深入了解国际经济热点</p>
                <p>• 同学们分组讨论，培养批判性思维</p>
                <p>• 分享最新学术论文，拓宽知识视野</p>
                <p>• 模拟学术会议，锻炼表达和演讲能力</p>
                <h3>活动收获</h3>
                <p>通过系列活动，同学们不仅加深了对专业知识的理解，还培养了独立思考和团队协作的能力，为未来的学术研究和职业发展打下坚实基础。</p>
            `
        },
        team: {
            icon: '🎉',
            title: '班级团建',
            date: '2025年',
            content: `
                <p>丰富的班级团建活动让我们的友谊更加深厚，班级凝聚力不断增强。</p>
                <h3>精彩瞬间</h3>
                <p>• 春游踏青：亲近自然，放松身心</p>
                <p>• 聚餐联谊：美食相聚，畅聊人生</p>
                <p>• 趣味运动会：竞技娱乐，增进友谊</p>
                <p>• 生日派对：温暖祝福，难忘回忆</p>
                <h3>班级氛围</h3>
                <p>这些活动不仅让我们在紧张的学习之余得到放松，更重要的是加深了彼此的了解，建立了深厚的同窗情谊，让国经2503班成为一个温暖有爱的大家庭。</p>
            `
        },
        sports: {
            icon: '🏆',
            title: '文体活动',
            date: '2025年',
            content: `
                <p>我们积极参与校内外各项文体竞赛，在比赛中展现班级风采和个人才华。</p>
                <h3>参与项目</h3>
                <p>• 篮球比赛：挥洒汗水，展现青春活力</p>
                <p>• 运动会：奋勇争先，为班争光</p>
                <p>• 文艺晚会：才艺展示，精彩纷呈</p>
                <p>• 辩论赛：辩思明理，口才出众</p>
                <h3>获得的荣誉</h3>
                <p>同学们在各种文体活动中表现优异，不仅收获了奖杯和荣誉，更重要的是锻炼了意志品质，培养了团队精神，展现了国经2503班积极向上、朝气蓬勃的班级风貌。</p>
            `
        }
    };

    // 活动详情模态框功能
    const modal = document.getElementById('activityModal');
    const closeBtn = document.querySelector('.modal-close');
    
    // 点击活动卡片打开详情
    document.querySelectorAll('.activity-card').forEach(card => {
        card.addEventListener('click', () => {
            const activityType = card.getAttribute('data-activity');
            const details = activityDetails[activityType];
            
            if (details) {
                document.getElementById('modalIcon').textContent = details.icon;
                document.getElementById('modalTitle').textContent = details.title;
                document.getElementById('modalDate').textContent = details.date;
                document.getElementById('modalBody').innerHTML = details.content;
                modal.classList.add('show');
                document.body.style.overflow = 'hidden';
            }
        });
    });
    
    // 关闭模态框
    if (closeBtn) {
        closeBtn.addEventListener('click', () => {
            modal.classList.remove('show');
            document.body.style.overflow = '';
        });
    }
    
    // 点击背景关闭模态框
    modal.addEventListener('click', (e) => {
        if (e.target === modal) {
            modal.classList.remove('show');
            document.body.style.overflow = '';
        }
    });
    
    // ESC键关闭模态框
    document.addEventListener('keydown', (e) => {
        if (e.key === 'Escape' && modal.classList.contains('show')) {
            modal.classList.remove('show');
            document.body.style.overflow = '';
        }
    });

    // 添加鼠标跟随效果（可选）
    let mouseX = 0;
    let mouseY = 0;

    document.addEventListener('mousemove', (e) => {
        mouseX = e.clientX;
        mouseY = e.clientY;
    });

    // 为浮动卡片添加动态效果
    document.querySelectorAll('.floating-card').forEach((card, index) => {
        card.addEventListener('mousemove', (e) => {
            const rect = card.getBoundingClientRect();
            const x = e.clientX - rect.left;
            const y = e.clientY - rect.top;
            
            const centerX = rect.width / 2;
            const centerY = rect.height / 2;
            
            const rotateX = (y - centerY) / 20;
            const rotateY = (centerX - x) / 20;
            
            card.style.transform = `perspective(1000px) rotateX(${rotateX}deg) rotateY(${rotateY}deg)`;
        });
        
        card.addEventListener('mouseleave', () => {
            card.style.transform = 'perspective(1000px) rotateX(0) rotateY(0)';
        });
    });

    console.log('半亩法塘 - 国经2503班网站已加载完成！');
});
